require("../../both/base.js")
require("./CourseNotesEdit.scss")

import DataTable from "../DataTabel/DataTable.jsx"

class CourseNotesEdit extends React.Component{
    constructor(props){
        super(props)

        const {init,courseId} = this.props
        init(courseId)

        this.state = {
            modalState : false,
            title : "",
            location : ""
        }

        this.addDisable = true
    }

    refreshWrap(){
        var self = this
        const {courseId,refresh} = self.props

        refresh(null,courseId)
    }

    delItemWrap(id){
        var self = this

        return function(e){
            if(! confirm("你确认删除此笔记吗？")){
                return
            }

            const {delNote} = self.props

            delNote(id)
        }
    }

    render(){
        let self = this
        const refreshWrap = this.refreshWrap.bind(this)

        const ths = ["笔记id","内容","作者id","操作"]

        // data trs
        const trs = self.props.courses.map((ele,idx) => {
            return <tr key={ele.id.toString()}>
                <td><div className="item">{ele.id}</div></td>
                <td><div className="item">{ele.text}</div></td>
                <td><div className="item">{ele.UserId}</div></td>
                <td><div className="item">
                    <div className="btn btn-danger" onClick={self.delItemWrap(ele.id)}>删除</div>
                </div></td>
            </tr>
        })

        return <div className="course_notes_edit_cr bln">
            <DataTable {...self.props}
                       ths={ths}
                       trs={trs}
                       searchPlaceHolder={"输入文字进行搜索"}
                       addDisable={true}
                       editDisable={true}
                       selectDisable={true}
                       editHref="#"
                       refresh={refreshWrap}
            />
        </div>
    }
}

export default CourseNotesEdit